// Copyright(c) 2016 Ruoyu Fan (Windy Darian), Xueyin Wan
// MIT License.

#ifndef _RENDERER_UTIL_H_
#define _RENDERER_UTIL_H_

#include <glm/glm.hpp>
#include <glm/gtx/hash.hpp>

#include <string>
#include <vector>
#include <tuple>
#include <memory>

namespace util
{
	template <class T>
	void hash_combine(std::size_t& seed, const T& v)
	{
		std::hash<T> hasher;
		seed ^= hasher(v) + 0x9e3779b9 + (seed << 6) + (seed >> 2);
	}

	template <typename str_t>
	std::string getResourcePath(str_t&& filename)
	{
		static std::string resource_folder = std::string(RESOURCE_PATH) + "/";
		return resource_folder + std::forward<str_t>(filename);
	}


	std::vector<char> readFile(const std::string& filename);

	constexpr float SMALL_NUMBER = 1e-8f;

	inline bool isNearlyEqual(float a, float b, float tolerance = SMALL_NUMBER)
	{
		return glm::abs(a - b) <= SMALL_NUMBER;
	}

	inline std::string findFolderName(const std::string& str)
	{
		return str.substr(0, str.find_last_of("/\\"));
	}

}

#endif